home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / tar-1_11.lha / tar-1.11.2 / getdate.c < prev    next >
C/C++ Source or Header  |  1993-03-15  |  47KB  |  1,855 lines

  1.  
  2. /*  A Bison parser, made from ./getdate.y  */
  3.  
  4. #define YYBISON 1  /* Identify Bison output.  */
  5.  
  6. #define    tAGO    258
  7. #define    tDAY    259
  8. #define    tDAYZONE    260
  9. #define    tID    261
  10. #define    tMERIDIAN    262
  11. #define    tMINUTE_UNIT    263
  12. #define    tMONTH    264
  13. #define    tMONTH_UNIT    265
  14. #define    tSEC_UNIT    266
  15. #define    tSNUMBER    267
  16. #define    tUNUMBER    268
  17. #define    tZONE    269
  18. #define    tDST    270
  19.  
  20. #line 1 "./getdate.y"
  21.  
  22. /* $Revision: 2.1 $
  23. **
  24. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  25. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  26. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  27. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  28. **  send any email to Rich.
  29. **
  30. **  This grammar has eight shift/reduce conflicts.
  31. **
  32. **  This code is in the public domain and has no copyright.
  33. */
  34. /* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */
  35. /* SUPPRESS 288 on yyerrlab *//* Label unused */
  36.  
  37. #ifdef HAVE_CONFIG_H
  38. #include "config.h"
  39. #endif
  40.  
  41. #ifdef __GNUC__
  42. #define alloca __builtin_alloca
  43. #else
  44. #ifdef HAVE_ALLOCA_H
  45. #include <alloca.h>
  46. #else
  47. #ifdef _AIX /* for Bison */
  48.  #pragma alloca
  49. #else
  50. char *alloca ();
  51. #endif
  52. #endif
  53. #endif
  54.  
  55. #include <stdio.h>
  56. #include <ctype.h>
  57.  
  58. /* The code at the top of get_date which figures out the offset of the
  59.    current time zone checks various CPP symbols to see if special
  60.    tricks are need, but defaults to using the gettimeofday system call.
  61.    Include <sys/time.h> if that will be used.  */
  62.  
  63. #if !defined (USG) && !defined (sgi) && !defined (__386BSD__)
  64. #include <sys/time.h>
  65. #endif
  66.  
  67. #if    defined(vms)
  68.  
  69. #include <types.h>
  70. #include <time.h>
  71.  
  72. #else
  73.  
  74. #include <sys/types.h>
  75.  
  76. #if    defined(USG) || !defined(HAVE_FTIME)
  77. /*
  78. **  If you need to do a tzset() call to set the
  79. **  timezone, and don't have ftime().
  80. */
  81. struct timeb {
  82.     time_t        time;        /* Seconds since the epoch    */
  83.     unsigned short    millitm;    /* Field not used        */
  84.     short        timezone;
  85.     short        dstflag;    /* Field not used        */
  86. };
  87.  
  88. #else
  89.  
  90. #include <sys/timeb.h>
  91.  
  92. #endif    /* defined(USG) && !defined(HAVE_FTIME) */
  93.  
  94. #if    defined(BSD4_2) || defined(BSD4_1C) || (defined (hp9000) && !defined (hpux))
  95. #include <sys/time.h>
  96. #else
  97. #if defined(_AIX)
  98. #include <sys/time.h>
  99. #endif
  100. #include <time.h>
  101. #endif    /* defined(BSD4_2) */
  102.  
  103. #endif    /* defined(vms) */
  104.  
  105. #if defined (STDC_HEADERS) || defined (USG)
  106. #include <string.h>
  107. #endif
  108.  
  109. #if sgi
  110. #undef timezone
  111. #endif
  112.  
  113. extern struct tm    *localtime();
  114.  
  115. #define yyparse getdate_yyparse
  116. #define yylex getdate_yylex
  117. #define yyerror getdate_yyerror
  118.  
  119. #if    !defined(lint) && !defined(SABER)
  120. static char RCS[] =
  121.     "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
  122. #endif    /* !defined(lint) && !defined(SABER) */
  123.  
  124.  
  125. #define EPOCH        1970
  126. #define HOUR(x)        ((time_t)(x) * 60)
  127. #define SECSPERDAY    (24L * 60L * 60L)
  128.  
  129.  
  130. /*
  131. **  An entry in the lexical lookup table.
  132. */
  133. typedef struct _TABLE {
  134.     char    *name;
  135.     int        type;
  136.     time_t    value;
  137. } TABLE;
  138.  
  139.  
  140. /*
  141. **  Daylight-savings mode:  on, off, or not yet known.
  142. */
  143. typedef enum _DSTMODE {
  144.     DSTon, DSToff, DSTmaybe
  145. } DSTMODE;
  146.  
  147. /*
  148. **  Meridian:  am, pm, or 24-hour style.
  149. */
  150. typedef enum _MERIDIAN {
  151.     MERam, MERpm, MER24
  152. } MERIDIAN;
  153.  
  154.  
  155. /*
  156. **  Global variables.  We could get rid of most of these by using a good
  157. **  union as the yacc stack.  (This routine was originally written before
  158. **  yacc had the %union construct.)  Maybe someday; right now we only use
  159. **  the %union very rarely.
  160. */
  161. static char    *yyInput;
  162. static DSTMODE    yyDSTmode;
  163. static time_t    yyDayOrdinal;
  164. static time_t    yyDayNumber;
  165. static int    yyHaveDate;
  166. static int    yyHaveDay;
  167. static int    yyHaveRel;
  168. static int    yyHaveTime;
  169. static int    yyHaveZone;
  170. static time_t    yyTimezone;
  171. static time_t    yyDay;
  172. static time_t    yyHour;
  173. static time_t    yyMinutes;
  174. static time_t    yyMonth;
  175. static time_t    yySeconds;
  176. static time_t    yyYear;
  177. static MERIDIAN    yyMeridian;
  178. static time_t    yyRelMonth;
  179. static time_t    yyRelSeconds;
  180.  
  181.  
  182. #line 163 "./getdate.y"
  183. typedef union {
  184.     time_t        Number;
  185.     enum _MERIDIAN    Meridian;
  186. } YYSTYPE;
  187.  
  188. #ifndef YYLTYPE
  189. typedef
  190.   struct yyltype
  191.     {
  192.       int timestamp;
  193.       int first_line;
  194.       int first_column;
  195.       int last_line;
  196.       int last_column;
  197.       char *text;
  198.    }
  199.   yyltype;
  200.  
  201. #define YYLTYPE yyltype
  202. #endif
  203.  
  204. #include <stdio.h>
  205.  
  206. #ifndef __STDC__
  207. #define const
  208. #endif
  209.  
  210.  
  211.  
  212. #define    YYFINAL        51
  213. #define    YYFLAG        -32768
  214. #define    YYNTBASE    19
  215.  
  216. #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 29)
  217.  
  218. static const char yytranslate[] = {     0,
  219.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  220.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  221.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  222.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  223.      2,     2,     2,    17,     2,     2,    18,     2,     2,     2,
  224.      2,     2,     2,     2,     2,     2,     2,    16,     2,     2,
  225.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  226.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  227.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  228.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  229.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  230.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  232.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  233.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  234.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  235.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  236.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  237.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  238.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  239.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  240.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  241.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  242.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  243.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  244.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  245.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15
  246. };
  247.  
  248. static const short yyprhs[] = {     0,
  249.      0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
  250.     24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
  251.     62,    68,    72,    75,    80,    83,    87,    90,    92,    95,
  252.     98,   100,   103,   106,   108,   111,   114,   116,   118,   119
  253. };
  254.  
  255. static const short yyrhs[] = {    -1,
  256.     19,    20,     0,    21,     0,    22,     0,    24,     0,    23,
  257.      0,    25,     0,    27,     0,    13,     7,     0,    13,    16,
  258.     13,    28,     0,    13,    16,    13,    12,     0,    13,    16,
  259.     13,    16,    13,    28,     0,    13,    16,    13,    16,    13,
  260.     12,     0,    14,     0,     5,     0,    14,    15,     0,     4,
  261.      0,     4,    17,     0,    13,     4,     0,    13,    18,    13,
  262.      0,    13,    18,    13,    18,    13,     0,    13,    12,    12,
  263.      0,     9,    13,     0,     9,    13,    17,    13,     0,    13,
  264.      9,     0,    13,     9,    13,     0,    26,     3,     0,    26,
  265.      0,    13,     8,     0,    12,     8,     0,     8,     0,    12,
  266.     11,     0,    13,    11,     0,    11,     0,    12,    10,     0,
  267.     13,    10,     0,    10,     0,    13,     0,     0,     7,     0
  268. };
  269.  
  270. #if YYDEBUG != 0
  271. static const short yyrline[] = { 0,
  272.    177,   178,   181,   184,   187,   190,   193,   196,   199,   205,
  273.    211,   218,   224,   234,   238,   242,   249,   253,   257,   263,
  274.    267,   272,   278,   282,   287,   291,   298,   302,   305,   308,
  275.    311,   314,   317,   320,   323,   326,   329,   334,   362,   365
  276. };
  277.  
  278. static const char * const yytname[] = {   "$","error","$illegal.","tAGO","tDAY",
  279. "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
  280. "tSNUMBER","tUNUMBER","tZONE","tDST","':'","','","'/'","spec","item","time",
  281. "zone","day","date","rel","relunit","number","o_merid",""
  282. };
  283. #endif
  284.  
  285. static const short yyr1[] = {     0,
  286.     19,    19,    20,    20,    20,    20,    20,    20,    21,    21,
  287.     21,    21,    21,    22,    22,    22,    23,    23,    23,    24,
  288.     24,    24,    24,    24,    24,    24,    25,    25,    26,    26,
  289.     26,    26,    26,    26,    26,    26,    26,    27,    28,    28
  290. };
  291.  
  292. static const short yyr2[] = {     0,
  293.      0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
  294.      4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
  295.      5,     3,     2,     4,     2,     3,     2,     1,     2,     2,
  296.      1,     2,     2,     1,     2,     2,     1,     1,     0,     1
  297. };
  298.  
  299. static const short yydefact[] = {     1,
  300.      0,    17,    15,    31,     0,    37,    34,     0,    38,    14,
  301.      2,     3,     4,     6,     5,     7,    28,     8,    18,    23,
  302.     30,    35,    32,    19,     9,    29,    25,    36,    33,     0,
  303.      0,     0,    16,    27,     0,    26,    22,    39,    20,    24,
  304.     40,    11,     0,    10,     0,    39,    21,    13,    12,     0,
  305.      0
  306. };
  307.  
  308. static const short yydefgoto[] = {     1,
  309.     11,    12,    13,    14,    15,    16,    17,    18,    44
  310. };
  311.  
  312. static const short yypact[] = {-32768,
  313.      0,   -15,-32768,-32768,   -10,-32768,-32768,    25,    11,    -8,
  314. -32768,-32768,-32768,-32768,-32768,-32768,    13,-32768,-32768,     7,
  315. -32768,-32768,-32768,-32768,-32768,-32768,     4,-32768,-32768,    14,
  316.     15,    19,-32768,-32768,    24,-32768,-32768,    18,    20,-32768,
  317. -32768,-32768,    26,-32768,    27,    -6,-32768,-32768,-32768,    31,
  318. -32768
  319. };
  320.  
  321. static const short yypgoto[] = {-32768,
  322. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
  323. };
  324.  
  325.  
  326. #define    YYLAST        41
  327.  
  328.  
  329. static const short yytable[] = {    50,
  330.     41,    19,    20,     2,     3,    48,    33,     4,     5,     6,
  331.      7,     8,     9,    10,    24,    34,    36,    25,    26,    27,
  332.     28,    29,    30,    35,    41,    37,    31,    38,    32,    42,
  333.     51,    39,    21,    43,    22,    23,    40,    45,    46,    47,
  334.     49
  335. };
  336.  
  337. static const short yycheck[] = {     0,
  338.      7,    17,    13,     4,     5,    12,    15,     8,     9,    10,
  339.     11,    12,    13,    14,     4,     3,    13,     7,     8,     9,
  340.     10,    11,    12,    17,     7,    12,    16,    13,    18,    12,
  341.      0,    13,     8,    16,    10,    11,    13,    18,    13,    13,
  342.     46
  343. };
  344. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  345. #line 3 "bison.simple"
  346.  
  347. /* Skeleton output parser for bison,
  348.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  349.  
  350.    This program is free software; you can redistribute it and/or modify
  351.    it under the terms of the GNU General Public License as published by
  352.    the Free Software Foundation; either version 1, or (at your option)
  353.    any later version.
  354.  
  355.    This program is distributed in the hope that it will be useful,
  356.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  357.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  358.    GNU General Public License for more details.
  359.  
  360.    You should have received a copy of the GNU General Public License
  361.    along with this program; if not, write to the Free Software
  362.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  363.  
  364.  
  365. #ifndef alloca
  366. #ifdef __GNUC__
  367. #define alloca __builtin_alloca
  368. #else /* not GNU C.  */
  369. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  370. #include <alloca.h>
  371. #else /* not sparc */
  372. #if defined (MSDOS) && !defined (__TURBOC__)
  373. #include <malloc.h>
  374. #else /* not MSDOS, or __TURBOC__ */
  375. #if defined(_AIX)
  376. #include <malloc.h>
  377.  #pragma alloca
  378. #endif /* not _AIX */
  379. #endif /* not MSDOS, or __TURBOC__ */
  380. #endif /* not sparc.  */
  381. #endif /* not GNU C.  */
  382. #endif /* alloca not defined.  */
  383.  
  384. /* This is the parser code that is written into each bison parser
  385.   when the %semantic_parser declaration is not specified in the grammar.
  386.   It was written by Richard Stallman by simplifying the hairy parser
  387.   used when %semantic_parser is specified.  */
  388.  
  389. /* Note: there must be only one dollar sign in this file.
  390.    It is replaced by the list of actions, each action
  391.    as one case of the switch.  */
  392.  
  393. #define yyerrok        (yyerrstatus = 0)
  394. #define yyclearin    (yychar = YYEMPTY)
  395. #define YYEMPTY        -2
  396. #define YYEOF        0
  397. #define YYACCEPT    return(0)
  398. #define YYABORT     return(1)
  399. #define YYERROR        goto yyerrlab1
  400. /* Like YYERROR except do call yyerror.
  401.    This remains here temporarily to ease the
  402.    transition to the new meaning of YYERROR, for GCC.
  403.    Once GCC version 2 has supplanted version 1, this can go.  */
  404. #define YYFAIL        goto yyerrlab
  405. #define YYRECOVERING()  (!!yyerrstatus)
  406. #define YYBACKUP(token, value) \
  407. do                                \
  408.   if (yychar == YYEMPTY && yylen == 1)                \
  409.     { yychar = (token), yylval = (value);            \
  410.       yychar1 = YYTRANSLATE (yychar);                \
  411.       YYPOPSTACK;                        \
  412.       goto yybackup;                        \
  413.     }                                \
  414.   else                                \
  415.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  416. while (0)
  417.  
  418. #define YYTERROR    1
  419. #define YYERRCODE    256
  420.  
  421. #ifndef YYPURE
  422. #define YYLEX        yylex()
  423. #endif
  424.  
  425. #ifdef YYPURE
  426. #ifdef YYLSP_NEEDED
  427. #define YYLEX        yylex(&yylval, &yylloc)
  428. #else
  429. #define YYLEX        yylex(&yylval)
  430. #endif
  431. #endif
  432.  
  433. /* If nonreentrant, generate the variables here */
  434.  
  435. #ifndef YYPURE
  436.  
  437. int    yychar;            /*  the lookahead symbol        */
  438. YYSTYPE    yylval;            /*  the semantic value of the        */
  439.                 /*  lookahead symbol            */
  440.  
  441. #ifdef YYLSP_NEEDED
  442. YYLTYPE yylloc;            /*  location data for the lookahead    */
  443.                 /*  symbol                */
  444. #endif
  445.  
  446. int yynerrs;            /*  number of parse errors so far       */
  447. #endif  /* not YYPURE */
  448.  
  449. #if YYDEBUG != 0
  450. int yydebug;            /*  nonzero means print parse trace    */
  451. /* Since this is uninitialized, it does not stop multiple parsers
  452.    from coexisting.  */
  453. #endif
  454.  
  455. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  456.  
  457. #ifndef    YYINITDEPTH
  458. #define YYINITDEPTH 200
  459. #endif
  460.  
  461. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  462.     (effective only if the built-in stack extension method is used).  */
  463.  
  464. #if YYMAXDEPTH == 0
  465. #undef YYMAXDEPTH
  466. #endif
  467.  
  468. #ifndef YYMAXDEPTH
  469. #define YYMAXDEPTH 10000
  470. #endif
  471.  
  472. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  473. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  474. #else                /* not GNU C or C++ */
  475. #ifndef __cplusplus
  476.  
  477. /* This is the most reliable way to avoid incompatibilities
  478.    in available built-in functions on various systems.  */
  479. static void
  480. __yy_bcopy (from, to, count)
  481.      char *from;
  482.      char *to;
  483.      int count;
  484. {
  485.   register char *f = from;
  486.   register char *t = to;
  487.   register int i = count;
  488.  
  489.   while (i-- > 0)
  490.     *t++ = *f++;
  491. }
  492.  
  493. #else /* __cplusplus */
  494.  
  495. /* This is the most reliable way to avoid incompatibilities
  496.    in available built-in functions on various systems.  */
  497. static void
  498. __yy_bcopy (char *from, char *to, int count)
  499. {
  500.   register char *f = from;
  501.   register char *t = to;
  502.   register int i = count;
  503.  
  504.   while (i-- > 0)
  505.     *t++ = *f++;
  506. }
  507.  
  508. #endif
  509. #endif
  510.  
  511. #line 169 "bison.simple"
  512. int
  513. yyparse()
  514. {
  515.   register int yystate;
  516.   register int yyn;
  517.   register short *yyssp;
  518.   register YYSTYPE *yyvsp;
  519.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  520.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  521.  
  522.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  523.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  524.  
  525.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  526.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  527.  
  528. #ifdef YYLSP_NEEDED
  529.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  530.   YYLTYPE *yyls = yylsa;
  531.   YYLTYPE *yylsp;
  532.  
  533. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  534. #else
  535. #define YYPOPSTACK   (yyvsp--, yyssp--)
  536. #endif
  537.  
  538.   int yystacksize = YYINITDEPTH;
  539.  
  540. #ifdef YYPURE
  541.   int yychar;
  542.   YYSTYPE yylval;
  543.   int yynerrs;
  544. #ifdef YYLSP_NEEDED
  545.   YYLTYPE yylloc;
  546. #endif
  547. #endif
  548.  
  549.   YYSTYPE yyval;        /*  the variable used to return        */
  550.                 /*  semantic values from the action    */
  551.                 /*  routines                */
  552.  
  553.   int yylen;
  554.  
  555. #if YYDEBUG != 0
  556.   if (yydebug)
  557.     fprintf(stderr, "Starting parse\n");
  558. #endif
  559.  
  560.   yystate = 0;
  561.   yyerrstatus = 0;
  562.   yynerrs = 0;
  563.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  564.  
  565.   /* Initialize stack pointers.
  566.      Waste one element of value and location stack
  567.      so that they stay on the same level as the state stack.  */
  568.  
  569.   yyssp = yyss - 1;
  570.   yyvsp = yyvs;
  571. #ifdef YYLSP_NEEDED
  572.   yylsp = yyls;
  573. #endif
  574.  
  575. /* Push a new state, which is found in  yystate  .  */
  576. /* In all cases, when you get here, the value and location stacks
  577.    have just been pushed. so pushing a state here evens the stacks.  */
  578. yynewstate:
  579.  
  580.   *++yyssp = yystate;
  581.  
  582.   if (yyssp >= yyss + yystacksize - 1)
  583.     {
  584.       /* Give user a chance to reallocate the stack */
  585.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  586.       YYSTYPE *yyvs1 = yyvs;
  587.       short *yyss1 = yyss;
  588. #ifdef YYLSP_NEEDED
  589.       YYLTYPE *yyls1 = yyls;
  590. #endif
  591.  
  592.       /* Get the current used size of the three stacks, in elements.  */
  593.       int size = yyssp - yyss + 1;
  594.  
  595. #ifdef yyoverflow
  596.       /* Each stack pointer address is followed by the size of
  597.      the data in use in that stack, in bytes.  */
  598.       yyoverflow("parser stack overflow",
  599.          &yyss1, size * sizeof (*yyssp),
  600.          &yyvs1, size * sizeof (*yyvsp),
  601. #ifdef YYLSP_NEEDED
  602.          &yyls1, size * sizeof (*yylsp),
  603. #endif
  604.          &yystacksize);
  605.  
  606.       yyss = yyss1; yyvs = yyvs1;
  607. #ifdef YYLSP_NEEDED
  608.       yyls = yyls1;
  609. #endif
  610. #else /* no yyoverflow */
  611.       /* Extend the stack our own way.  */
  612.       if (yystacksize >= YYMAXDEPTH)
  613.     {
  614.       yyerror("parser stack overflow");
  615.       return 2;
  616.     }
  617.       yystacksize *= 2;
  618.       if (yystacksize > YYMAXDEPTH)
  619.     yystacksize = YYMAXDEPTH;
  620.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  621.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  622.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  623.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  624. #ifdef YYLSP_NEEDED
  625.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  626.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  627. #endif
  628. #endif /* no yyoverflow */
  629.  
  630.       yyssp = yyss + size - 1;
  631.       yyvsp = yyvs + size - 1;
  632. #ifdef YYLSP_NEEDED
  633.       yylsp = yyls + size - 1;
  634. #endif
  635.  
  636. #if YYDEBUG != 0
  637.       if (yydebug)
  638.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  639. #endif
  640.  
  641.       if (yyssp >= yyss + yystacksize - 1)
  642.     YYABORT;
  643.     }
  644.  
  645. #if YYDEBUG != 0
  646.   if (yydebug)
  647.     fprintf(stderr, "Entering state %d\n", yystate);
  648. #endif
  649.  
  650.  yybackup:
  651.  
  652. /* Do appropriate processing given the current state.  */
  653. /* Read a lookahead token if we need one and don't already have one.  */
  654. /* yyresume: */
  655.  
  656.   /* First try to decide what to do without reference to lookahead token.  */
  657.  
  658.   yyn = yypact[yystate];
  659.   if (yyn == YYFLAG)
  660.     goto yydefault;
  661.  
  662.   /* Not known => get a lookahead token if don't already have one.  */
  663.  
  664.   /* yychar is either YYEMPTY or YYEOF
  665.      or a valid token in external form.  */
  666.  
  667.   if (yychar == YYEMPTY)
  668.     {
  669. #if YYDEBUG != 0
  670.       if (yydebug)
  671.     fprintf(stderr, "Reading a token: ");
  672. #endif
  673.       yychar = YYLEX;
  674.     }
  675.  
  676.   /* Convert token to internal form (in yychar1) for indexing tables with */
  677.  
  678.   if (yychar <= 0)        /* This means end of input. */
  679.     {
  680.       yychar1 = 0;
  681.       yychar = YYEOF;        /* Don't call YYLEX any more */
  682.  
  683. #if YYDEBUG != 0
  684.       if (yydebug)
  685.     fprintf(stderr, "Now at end of input.\n");
  686. #endif
  687.     }
  688.   else
  689.     {
  690.       yychar1 = YYTRANSLATE(yychar);
  691.  
  692. #if YYDEBUG != 0
  693.       if (yydebug)
  694.     {
  695.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  696.       /* Give the individual parser a way to print the precise meaning
  697.          of a token, for further debugging info.  */
  698. #ifdef YYPRINT
  699.       YYPRINT (stderr, yychar, yylval);
  700. #endif
  701.       fprintf (stderr, ")\n");
  702.     }
  703. #endif
  704.     }
  705.  
  706.   yyn += yychar1;
  707.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  708.     goto yydefault;
  709.  
  710.   yyn = yytable[yyn];
  711.  
  712.   /* yyn is what to do for this token type in this state.
  713.      Negative => reduce, -yyn is rule number.
  714.      Positive => shift, yyn is new state.
  715.        New state is final state => don't bother to shift,
  716.        just return success.
  717.      0, or most negative number => error.  */
  718.  
  719.   if (yyn < 0)
  720.     {
  721.       if (yyn == YYFLAG)
  722.     goto yyerrlab;
  723.       yyn = -yyn;
  724.       goto yyreduce;
  725.     }
  726.   else if (yyn == 0)
  727.     goto yyerrlab;
  728.  
  729.   if (yyn == YYFINAL)
  730.     YYACCEPT;
  731.  
  732.   /* Shift the lookahead token.  */
  733.  
  734. #if YYDEBUG != 0
  735.   if (yydebug)
  736.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  737. #endif
  738.  
  739.   /* Discard the token being shifted unless it is eof.  */
  740.   if (yychar != YYEOF)
  741.     yychar = YYEMPTY;
  742.  
  743.   *++yyvsp = yylval;
  744. #ifdef YYLSP_NEEDED
  745.   *++yylsp = yylloc;
  746. #endif
  747.  
  748.   /* count tokens shifted since error; after three, turn off error status.  */
  749.   if (yyerrstatus) yyerrstatus--;
  750.  
  751.   yystate = yyn;
  752.   goto yynewstate;
  753.  
  754. /* Do the default action for the current state.  */
  755. yydefault:
  756.  
  757.   yyn = yydefact[yystate];
  758.   if (yyn == 0)
  759.     goto yyerrlab;
  760.  
  761. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  762. yyreduce:
  763.   yylen = yyr2[yyn];
  764.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  765.  
  766. #if YYDEBUG != 0
  767.   if (yydebug)
  768.     {
  769.       int i;
  770.  
  771.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  772.            yyn, yyrline[yyn]);
  773.  
  774.       /* Print the symboles being reduced, and their result.  */
  775.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  776.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  777.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  778.     }
  779. #endif
  780.  
  781.  
  782.   switch (yyn) {
  783.  
  784. case 3:
  785. #line 181 "./getdate.y"
  786. {
  787.         yyHaveTime++;
  788.     ;
  789.     break;}
  790. case 4:
  791. #line 184 "./getdate.y"
  792. {
  793.         yyHaveZone++;
  794.     ;
  795.     break;}
  796. case 5:
  797. #line 187 "./getdate.y"
  798. {
  799.         yyHaveDate++;
  800.     ;
  801.     break;}
  802. case 6:
  803. #line 190 "./getdate.y"
  804. {
  805.         yyHaveDay++;
  806.     ;
  807.     break;}
  808. case 7:
  809. #line 193 "./getdate.y"
  810. {
  811.         yyHaveRel++;
  812.     ;
  813.     break;}
  814. case 9:
  815. #line 199 "./getdate.y"
  816. {
  817.         yyHour = yyvsp[-1].Number;
  818.         yyMinutes = 0;
  819.         yySeconds = 0;
  820.         yyMeridian = yyvsp[0].Meridian;
  821.     ;
  822.     break;}
  823. case 10:
  824. #line 205 "./getdate.y"
  825. {
  826.         yyHour = yyvsp[-3].Number;
  827.         yyMinutes = yyvsp[-1].Number;
  828.         yySeconds = 0;
  829.         yyMeridian = yyvsp[0].Meridian;
  830.     ;
  831.     break;}
  832. case 11:
  833. #line 211 "./getdate.y"
  834. {
  835.         yyHour = yyvsp[-3].Number;
  836.         yyMinutes = yyvsp[-1].Number;
  837.         yyMeridian = MER24;
  838.         yyDSTmode = DSToff;
  839.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  840.     ;
  841.     break;}
  842. case 12:
  843. #line 218 "./getdate.y"
  844. {
  845.         yyHour = yyvsp[-5].Number;
  846.         yyMinutes = yyvsp[-3].Number;
  847.         yySeconds = yyvsp[-1].Number;
  848.         yyMeridian = yyvsp[0].Meridian;
  849.     ;
  850.     break;}
  851. case 13:
  852. #line 224 "./getdate.y"
  853. {
  854.         yyHour = yyvsp[-5].Number;
  855.         yyMinutes = yyvsp[-3].Number;
  856.         yySeconds = yyvsp[-1].Number;
  857.         yyMeridian = MER24;
  858.         yyDSTmode = DSToff;
  859.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  860.     ;
  861.     break;}
  862. case 14:
  863. #line 234 "./getdate.y"
  864. {
  865.         yyTimezone = yyvsp[0].Number;
  866.         yyDSTmode = DSToff;
  867.     ;
  868.     break;}
  869. case 15:
  870. #line 238 "./getdate.y"
  871. {
  872.         yyTimezone = yyvsp[0].Number;
  873.         yyDSTmode = DSTon;
  874.     ;
  875.     break;}
  876. case 16:
  877. #line 243 "./getdate.y"
  878. {
  879.         yyTimezone = yyvsp[-1].Number;
  880.         yyDSTmode = DSTon;
  881.     ;
  882.     break;}
  883. case 17:
  884. #line 249 "./getdate.y"
  885. {
  886.         yyDayOrdinal = 1;
  887.         yyDayNumber = yyvsp[0].Number;
  888.     ;
  889.     break;}
  890. case 18:
  891. #line 253 "./getdate.y"
  892. {
  893.         yyDayOrdinal = 1;
  894.         yyDayNumber = yyvsp[-1].Number;
  895.     ;
  896.     break;}
  897. case 19:
  898. #line 257 "./getdate.y"
  899. {
  900.         yyDayOrdinal = yyvsp[-1].Number;
  901.         yyDayNumber = yyvsp[0].Number;
  902.     ;
  903.     break;}
  904. case 20:
  905. #line 263 "./getdate.y"
  906. {
  907.         yyMonth = yyvsp[-2].Number;
  908.         yyDay = yyvsp[0].Number;
  909.     ;
  910.     break;}
  911. case 21:
  912. #line 267 "./getdate.y"
  913. {
  914.         yyMonth = yyvsp[-4].Number;
  915.         yyDay = yyvsp[-2].Number;
  916.         yyYear = yyvsp[0].Number;
  917.     ;
  918.     break;}
  919. case 22:
  920. #line 272 "./getdate.y"
  921. {
  922.         /* ISO 8601 format.  yyyy-mm-dd.  */
  923.         yyYear = yyvsp[-2].Number;
  924.         yyMonth = -yyvsp[-1].Number;
  925.         yyDay = -yyvsp[0].Number;
  926.     ;
  927.     break;}
  928. case 23:
  929. #line 278 "./getdate.y"
  930. {
  931.         yyMonth = yyvsp[-1].Number;
  932.         yyDay = yyvsp[0].Number;
  933.     ;
  934.     break;}
  935. case 24:
  936. #line 282 "./getdate.y"
  937. {
  938.         yyMonth = yyvsp[-3].Number;
  939.         yyDay = yyvsp[-2].Number;
  940.         yyYear = yyvsp[0].Number;
  941.     ;
  942.     break;}
  943. case 25:
  944. #line 287 "./getdate.y"
  945. {
  946.         yyMonth = yyvsp[0].Number;
  947.         yyDay = yyvsp[-1].Number;
  948.     ;
  949.     break;}
  950. case 26:
  951. #line 291 "./getdate.y"
  952. {
  953.         yyMonth = yyvsp[-1].Number;
  954.         yyDay = yyvsp[-2].Number;
  955.         yyYear = yyvsp[0].Number;
  956.     ;
  957.     break;}
  958. case 27:
  959. #line 298 "./getdate.y"
  960. {
  961.         yyRelSeconds = -yyRelSeconds;
  962.         yyRelMonth = -yyRelMonth;
  963.     ;
  964.     break;}
  965. case 29:
  966. #line 305 "./getdate.y"
  967. {
  968.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  969.     ;
  970.     break;}
  971. case 30:
  972. #line 308 "./getdate.y"
  973. {
  974.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  975.     ;
  976.     break;}
  977. case 31:
  978. #line 311 "./getdate.y"
  979. {
  980.         yyRelSeconds += yyvsp[0].Number * 60L;
  981.     ;
  982.     break;}
  983. case 32:
  984. #line 314 "./getdate.y"
  985. {
  986.         yyRelSeconds += yyvsp[-1].Number;
  987.     ;
  988.     break;}
  989. case 33:
  990. #line 317 "./getdate.y"
  991. {
  992.         yyRelSeconds += yyvsp[-1].Number;
  993.     ;
  994.     break;}
  995. case 34:
  996. #line 320 "./getdate.y"
  997. {
  998.         yyRelSeconds++;
  999.     ;
  1000.     break;}
  1001. case 35:
  1002. #line 323 "./getdate.y"
  1003. {
  1004.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1005.     ;
  1006.     break;}
  1007. case 36:
  1008. #line 326 "./getdate.y"
  1009. {
  1010.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1011.     ;
  1012.     break;}
  1013. case 37:
  1014. #line 329 "./getdate.y"
  1015. {
  1016.         yyRelMonth += yyvsp[0].Number;
  1017.     ;
  1018.     break;}
  1019. case 38:
  1020. #line 334 "./getdate.y"
  1021. {
  1022.         if (yyHaveTime && yyHaveDate && !yyHaveRel)
  1023.         yyYear = yyvsp[0].Number;
  1024.         else {
  1025.         if(yyvsp[0].Number>10000) {
  1026.             time_t date_part;
  1027.  
  1028.             date_part= yyvsp[0].Number/10000;
  1029.             yyHaveDate++;
  1030.             yyDay= (date_part)%100;
  1031.             yyMonth= (date_part/100)%100;
  1032.             yyYear = date_part/10000;
  1033.         } 
  1034.             yyHaveTime++;
  1035.         if (yyvsp[0].Number < 100) {
  1036.             yyHour = yyvsp[0].Number;
  1037.             yyMinutes = 0;
  1038.         }
  1039.         else {
  1040.             yyHour = yyvsp[0].Number / 100;
  1041.             yyMinutes = yyvsp[0].Number % 100;
  1042.         }
  1043.         yySeconds = 0;
  1044.         yyMeridian = MER24;
  1045.         }
  1046.     ;
  1047.     break;}
  1048. case 39:
  1049. #line 362 "./getdate.y"
  1050. {
  1051.         yyval.Meridian = MER24;
  1052.     ;
  1053.     break;}
  1054. case 40:
  1055. #line 365 "./getdate.y"
  1056. {
  1057.         yyval.Meridian = yyvsp[0].Meridian;
  1058.     ;
  1059.     break;}
  1060. }
  1061.    /* the action file gets copied in in place of this dollarsign */
  1062. #line 440 "bison.simple"
  1063.  
  1064.   yyvsp -= yylen;
  1065.   yyssp -= yylen;
  1066. #ifdef YYLSP_NEEDED
  1067.   yylsp -= yylen;
  1068. #endif
  1069.  
  1070. #if YYDEBUG != 0
  1071.   if (yydebug)
  1072.     {
  1073.       short *ssp1 = yyss - 1;
  1074.       fprintf (stderr, "state stack now");
  1075.       while (ssp1 != yyssp)
  1076.     fprintf (stderr, " %d", *++ssp1);
  1077.       fprintf (stderr, "\n");
  1078.     }
  1079. #endif
  1080.  
  1081.   *++yyvsp = yyval;
  1082.  
  1083. #ifdef YYLSP_NEEDED
  1084.   yylsp++;
  1085.   if (yylen == 0)
  1086.     {
  1087.       yylsp->first_line = yylloc.first_line;
  1088.       yylsp->first_column = yylloc.first_column;
  1089.       yylsp->last_line = (yylsp-1)->last_line;
  1090.       yylsp->last_column = (yylsp-1)->last_column;
  1091.       yylsp->text = 0;
  1092.     }
  1093.   else
  1094.     {
  1095.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1096.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1097.     }
  1098. #endif
  1099.  
  1100.   /* Now "shift" the result of the reduction.
  1101.      Determine what state that goes to,
  1102.      based on the state we popped back to
  1103.      and the rule number reduced by.  */
  1104.  
  1105.   yyn = yyr1[yyn];
  1106.  
  1107.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1108.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1109.     yystate = yytable[yystate];
  1110.   else
  1111.     yystate = yydefgoto[yyn - YYNTBASE];
  1112.  
  1113.   goto yynewstate;
  1114.  
  1115. yyerrlab:   /* here on detecting error */
  1116.  
  1117.   if (! yyerrstatus)
  1118.     /* If not already recovering from an error, report this error.  */
  1119.     {
  1120.       ++yynerrs;
  1121.  
  1122. #ifdef YYERROR_VERBOSE
  1123.       yyn = yypact[yystate];
  1124.  
  1125.       if (yyn > YYFLAG && yyn < YYLAST)
  1126.     {
  1127.       int size = 0;
  1128.       char *msg;
  1129.       int x, count;
  1130.  
  1131.       count = 0;
  1132.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1133.         if (yycheck[x + yyn] == x)
  1134.           size += strlen(yytname[x]) + 15, count++;
  1135.       msg = (char *) malloc(size + 15);
  1136.       if (msg != 0)
  1137.         {
  1138.           strcpy(msg, "parse error");
  1139.  
  1140.           if (count < 5)
  1141.         {
  1142.           count = 0;
  1143.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1144.             if (yycheck[x + yyn] == x)
  1145.               {
  1146.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1147.             strcat(msg, yytname[x]);
  1148.             strcat(msg, "'");
  1149.             count++;
  1150.               }
  1151.         }
  1152.           yyerror(msg);
  1153.           free(msg);
  1154.         }
  1155.       else
  1156.         yyerror ("parse error; also virtual memory exceeded");
  1157.     }
  1158.       else
  1159. #endif /* YYERROR_VERBOSE */
  1160.     yyerror("parse error");
  1161.     }
  1162.  
  1163. yyerrlab1:   /* here on error raised explicitly by an action */
  1164.  
  1165.   if (yyerrstatus == 3)
  1166.     {
  1167.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1168.  
  1169.       /* return failure if at end of input */
  1170.       if (yychar == YYEOF)
  1171.     YYABORT;
  1172.  
  1173. #if YYDEBUG != 0
  1174.       if (yydebug)
  1175.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1176. #endif
  1177.  
  1178.       yychar = YYEMPTY;
  1179.     }
  1180.  
  1181.   /* Else will try to reuse lookahead token
  1182.      after shifting the error token.  */
  1183.  
  1184.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1185.  
  1186.   goto yyerrhandle;
  1187.  
  1188. yyerrdefault:  /* current state does not do anything special for the error token. */
  1189.  
  1190. #if 0
  1191.   /* This is wrong; only states that explicitly want error tokens
  1192.      should shift them.  */
  1193.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1194.   if (yyn) goto yydefault;
  1195. #endif
  1196.  
  1197. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1198.  
  1199.   if (yyssp == yyss) YYABORT;
  1200.   yyvsp--;
  1201.   yystate = *--yyssp;
  1202. #ifdef YYLSP_NEEDED
  1203.   yylsp--;
  1204. #endif
  1205.  
  1206. #if YYDEBUG != 0
  1207.   if (yydebug)
  1208.     {
  1209.       short *ssp1 = yyss - 1;
  1210.       fprintf (stderr, "Error: state stack now");
  1211.       while (ssp1 != yyssp)
  1212.     fprintf (stderr, " %d", *++ssp1);
  1213.       fprintf (stderr, "\n");
  1214.     }
  1215. #endif
  1216.  
  1217. yyerrhandle:
  1218.  
  1219.   yyn = yypact[yystate];
  1220.   if (yyn == YYFLAG)
  1221.     goto yyerrdefault;
  1222.  
  1223.   yyn += YYTERROR;
  1224.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1225.     goto yyerrdefault;
  1226.  
  1227.   yyn = yytable[yyn];
  1228.   if (yyn < 0)
  1229.     {
  1230.       if (yyn == YYFLAG)
  1231.     goto yyerrpop;
  1232.       yyn = -yyn;
  1233.       goto yyreduce;
  1234.     }
  1235.   else if (yyn == 0)
  1236.     goto yyerrpop;
  1237.  
  1238.   if (yyn == YYFINAL)
  1239.     YYACCEPT;
  1240.  
  1241. #if YYDEBUG != 0
  1242.   if (yydebug)
  1243.     fprintf(stderr, "Shifting error token, ");
  1244. #endif
  1245.  
  1246.   *++yyvsp = yylval;
  1247. #ifdef YYLSP_NEEDED
  1248.   *++yylsp = yylloc;
  1249. #endif
  1250.  
  1251.   yystate = yyn;
  1252.   goto yynewstate;
  1253. }
  1254. #line 370 "./getdate.y"
  1255.  
  1256.  
  1257. /* Month and day table. */
  1258. static TABLE const MonthDayTable[] = {
  1259.     { "january",    tMONTH,  1 },
  1260.     { "february",    tMONTH,  2 },
  1261.     { "march",        tMONTH,  3 },
  1262.     { "april",        tMONTH,  4 },
  1263.     { "may",        tMONTH,  5 },
  1264.     { "june",        tMONTH,  6 },
  1265.     { "july",        tMONTH,  7 },
  1266.     { "august",        tMONTH,  8 },
  1267.     { "september",    tMONTH,  9 },
  1268.     { "sept",        tMONTH,  9 },
  1269.     { "october",    tMONTH, 10 },
  1270.     { "november",    tMONTH, 11 },
  1271.     { "december",    tMONTH, 12 },
  1272.     { "sunday",        tDAY, 0 },
  1273.     { "monday",        tDAY, 1 },
  1274.     { "tuesday",    tDAY, 2 },
  1275.     { "tues",        tDAY, 2 },
  1276.     { "wednesday",    tDAY, 3 },
  1277.     { "wednes",        tDAY, 3 },
  1278.     { "thursday",    tDAY, 4 },
  1279.     { "thur",        tDAY, 4 },
  1280.     { "thurs",        tDAY, 4 },
  1281.     { "friday",        tDAY, 5 },
  1282.     { "saturday",    tDAY, 6 },
  1283.     { NULL }
  1284. };
  1285.  
  1286. /* Time units table. */
  1287. static TABLE const UnitsTable[] = {
  1288.     { "year",        tMONTH_UNIT,    12 },
  1289.     { "month",        tMONTH_UNIT,    1 },
  1290.     { "fortnight",    tMINUTE_UNIT,    14 * 24 * 60 },
  1291.     { "week",        tMINUTE_UNIT,    7 * 24 * 60 },
  1292.     { "day",        tMINUTE_UNIT,    1 * 24 * 60 },
  1293.     { "hour",        tMINUTE_UNIT,    60 },
  1294.     { "minute",        tMINUTE_UNIT,    1 },
  1295.     { "min",        tMINUTE_UNIT,    1 },
  1296.     { "second",        tSEC_UNIT,    1 },
  1297.     { "sec",        tSEC_UNIT,    1 },
  1298.     { NULL }
  1299. };
  1300.  
  1301. /* Assorted relative-time words. */
  1302. static TABLE const OtherTable[] = {
  1303.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  1304.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  1305.     { "today",        tMINUTE_UNIT,    0 },
  1306.     { "now",        tMINUTE_UNIT,    0 },
  1307.     { "last",        tUNUMBER,    -1 },
  1308.     { "this",        tMINUTE_UNIT,    0 },
  1309.     { "next",        tUNUMBER,    2 },
  1310.     { "first",        tUNUMBER,    1 },
  1311. /*  { "second",        tUNUMBER,    2 }, */
  1312.     { "third",        tUNUMBER,    3 },
  1313.     { "fourth",        tUNUMBER,    4 },
  1314.     { "fifth",        tUNUMBER,    5 },
  1315.     { "sixth",        tUNUMBER,    6 },
  1316.     { "seventh",    tUNUMBER,    7 },
  1317.     { "eighth",        tUNUMBER,    8 },
  1318.     { "ninth",        tUNUMBER,    9 },
  1319.     { "tenth",        tUNUMBER,    10 },
  1320.     { "eleventh",    tUNUMBER,    11 },
  1321.     { "twelfth",    tUNUMBER,    12 },
  1322.     { "ago",        tAGO,    1 },
  1323.     { NULL }
  1324. };
  1325.  
  1326. /* The timezone table. */
  1327. /* Some of these are commented out because a time_t can't store a float. */
  1328. static TABLE const TimezoneTable[] = {
  1329.     { "gmt",    tZONE,     HOUR( 0) },    /* Greenwich Mean */
  1330.     { "ut",    tZONE,     HOUR( 0) },    /* Universal (Coordinated) */
  1331.     { "utc",    tZONE,     HOUR( 0) },
  1332.     { "wet",    tZONE,     HOUR( 0) },    /* Western European */
  1333.     { "bst",    tDAYZONE,  HOUR( 0) },    /* British Summer */
  1334.     { "wat",    tZONE,     HOUR( 1) },    /* West Africa */
  1335.     { "at",    tZONE,     HOUR( 2) },    /* Azores */
  1336. #if    0
  1337.     /* For completeness.  BST is also British Summer, and GST is
  1338.      * also Guam Standard. */
  1339.     { "bst",    tZONE,     HOUR( 3) },    /* Brazil Standard */
  1340.     { "gst",    tZONE,     HOUR( 3) },    /* Greenland Standard */
  1341. #endif
  1342. #if 0
  1343.     { "nft",    tZONE,     HOUR(3.5) },    /* Newfoundland */
  1344.     { "nst",    tZONE,     HOUR(3.5) },    /* Newfoundland Standard */
  1345.     { "ndt",    tDAYZONE,  HOUR(3.5) },    /* Newfoundland Daylight */
  1346. #endif
  1347.     { "ast",    tZONE,     HOUR( 4) },    /* Atlantic Standard */
  1348.     { "adt",    tDAYZONE,  HOUR( 4) },    /* Atlantic Daylight */
  1349.     { "est",    tZONE,     HOUR( 5) },    /* Eastern Standard */
  1350.     { "edt",    tDAYZONE,  HOUR( 5) },    /* Eastern Daylight */
  1351.     { "cst",    tZONE,     HOUR( 6) },    /* Central Standard */
  1352.     { "cdt",    tDAYZONE,  HOUR( 6) },    /* Central Daylight */
  1353.     { "mst",    tZONE,     HOUR( 7) },    /* Mountain Standard */
  1354.     { "mdt",    tDAYZONE,  HOUR( 7) },    /* Mountain Daylight */
  1355.     { "pst",    tZONE,     HOUR( 8) },    /* Pacific Standard */
  1356.     { "pdt",    tDAYZONE,  HOUR( 8) },    /* Pacific Daylight */
  1357.     { "yst",    tZONE,     HOUR( 9) },    /* Yukon Standard */
  1358.     { "ydt",    tDAYZONE,  HOUR( 9) },    /* Yukon Daylight */
  1359.     { "hst",    tZONE,     HOUR(10) },    /* Hawaii Standard */
  1360.     { "hdt",    tDAYZONE,  HOUR(10) },    /* Hawaii Daylight */
  1361.     { "cat",    tZONE,     HOUR(10) },    /* Central Alaska */
  1362.     { "ahst",    tZONE,     HOUR(10) },    /* Alaska-Hawaii Standard */
  1363.     { "nt",    tZONE,     HOUR(11) },    /* Nome */
  1364.     { "idlw",    tZONE,     HOUR(12) },    /* International Date Line West */
  1365.     { "cet",    tZONE,     -HOUR(1) },    /* Central European */
  1366.     { "met",    tZONE,     -HOUR(1) },    /* Middle European */
  1367.     { "mewt",    tZONE,     -HOUR(1) },    /* Middle European Winter */
  1368.     { "mest",    tDAYZONE,  -HOUR(1) },    /* Middle European Summer */
  1369.     { "swt",    tZONE,     -HOUR(1) },    /* Swedish Winter */
  1370.     { "sst",    tDAYZONE,  -HOUR(1) },    /* Swedish Summer */
  1371.     { "fwt",    tZONE,     -HOUR(1) },    /* French Winter */
  1372.     { "fst",    tDAYZONE,  -HOUR(1) },    /* French Summer */
  1373.     { "eet",    tZONE,     -HOUR(2) },    /* Eastern Europe, USSR Zone 1 */
  1374.     { "bt",    tZONE,     -HOUR(3) },    /* Baghdad, USSR Zone 2 */
  1375. #if 0
  1376.     { "it",    tZONE,     -HOUR(3.5) },/* Iran */
  1377. #endif
  1378.     { "zp4",    tZONE,     -HOUR(4) },    /* USSR Zone 3 */
  1379.     { "zp5",    tZONE,     -HOUR(5) },    /* USSR Zone 4 */
  1380. #if 0
  1381.     { "ist",    tZONE,     -HOUR(5.5) },/* Indian Standard */
  1382. #endif
  1383.     { "zp6",    tZONE,     -HOUR(6) },    /* USSR Zone 5 */
  1384. #if    0
  1385.     /* For completeness.  NST is also Newfoundland Stanard, and SST is
  1386.      * also Swedish Summer. */
  1387.     { "nst",    tZONE,     -HOUR(6.5) },/* North Sumatra */
  1388.     { "sst",    tZONE,     -HOUR(7) },    /* South Sumatra, USSR Zone 6 */
  1389. #endif    /* 0 */
  1390.     { "wast",    tZONE,     -HOUR(7) },    /* West Australian Standard */
  1391.     { "wadt",    tDAYZONE,  -HOUR(7) },    /* West Australian Daylight */
  1392. #if 0
  1393.     { "jt",    tZONE,     -HOUR(7.5) },/* Java (3pm in Cronusland!) */
  1394. #endif
  1395.     { "cct",    tZONE,     -HOUR(8) },    /* China Coast, USSR Zone 7 */
  1396.     { "jst",    tZONE,     -HOUR(9) },    /* Japan Standard, USSR Zone 8 */
  1397. #if 0
  1398.     { "cast",    tZONE,     -HOUR(9.5) },/* Central Australian Standard */
  1399.     { "cadt",    tDAYZONE,  -HOUR(9.5) },/* Central Australian Daylight */
  1400. #endif
  1401.     { "east",    tZONE,     -HOUR(10) },    /* Eastern Australian Standard */
  1402.     { "eadt",    tDAYZONE,  -HOUR(10) },    /* Eastern Australian Daylight */
  1403.     { "gst",    tZONE,     -HOUR(10) },    /* Guam Standard, USSR Zone 9 */
  1404.     { "nzt",    tZONE,     -HOUR(12) },    /* New Zealand */
  1405.     { "nzst",    tZONE,     -HOUR(12) },    /* New Zealand Standard */
  1406.     { "nzdt",    tDAYZONE,  -HOUR(12) },    /* New Zealand Daylight */
  1407.     { "idle",    tZONE,     -HOUR(12) },    /* International Date Line East */
  1408.     {  NULL  }
  1409. };
  1410.  
  1411. /* Military timezone table. */
  1412. static TABLE const MilitaryTable[] = {
  1413.     { "a",    tZONE,    HOUR(  1) },
  1414.     { "b",    tZONE,    HOUR(  2) },
  1415.     { "c",    tZONE,    HOUR(  3) },
  1416.     { "d",    tZONE,    HOUR(  4) },
  1417.     { "e",    tZONE,    HOUR(  5) },
  1418.     { "f",    tZONE,    HOUR(  6) },
  1419.     { "g",    tZONE,    HOUR(  7) },
  1420.     { "h",    tZONE,    HOUR(  8) },
  1421.     { "i",    tZONE,    HOUR(  9) },
  1422.     { "k",    tZONE,    HOUR( 10) },
  1423.     { "l",    tZONE,    HOUR( 11) },
  1424.     { "m",    tZONE,    HOUR( 12) },
  1425.     { "n",    tZONE,    HOUR(- 1) },
  1426.     { "o",    tZONE,    HOUR(- 2) },
  1427.     { "p",    tZONE,    HOUR(- 3) },
  1428.     { "q",    tZONE,    HOUR(- 4) },
  1429.     { "r",    tZONE,    HOUR(- 5) },
  1430.     { "s",    tZONE,    HOUR(- 6) },
  1431.     { "t",    tZONE,    HOUR(- 7) },
  1432.     { "u",    tZONE,    HOUR(- 8) },
  1433.     { "v",    tZONE,    HOUR(- 9) },
  1434.     { "w",    tZONE,    HOUR(-10) },
  1435.     { "x",    tZONE,    HOUR(-11) },
  1436.     { "y",    tZONE,    HOUR(-12) },
  1437.     { "z",    tZONE,    HOUR(  0) },
  1438.     { NULL }
  1439. };
  1440.  
  1441.  
  1442.  
  1443.  
  1444. /* ARGSUSED */
  1445. static int
  1446. yyerror(s)
  1447.     char    *s;
  1448. {
  1449.   return 0;
  1450. }
  1451.  
  1452.  
  1453. static time_t
  1454. ToSeconds(Hours, Minutes, Seconds, Meridian)
  1455.     time_t    Hours;
  1456.     time_t    Minutes;
  1457.     time_t    Seconds;
  1458.     MERIDIAN    Meridian;
  1459. {
  1460.     if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
  1461.     return -1;
  1462.     switch (Meridian) {
  1463.     case MER24:
  1464.     if (Hours < 0 || Hours > 23)
  1465.         return -1;
  1466.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1467.     case MERam:
  1468.     if (Hours < 1 || Hours > 12)
  1469.         return -1;
  1470.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1471.     case MERpm:
  1472.     if (Hours < 1 || Hours > 12)
  1473.         return -1;
  1474.     return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
  1475.     }
  1476.     /* NOTREACHED */
  1477. }
  1478.  
  1479.  
  1480. static time_t
  1481. Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
  1482.     time_t    Month;
  1483.     time_t    Day;
  1484.     time_t    Year;
  1485.     time_t    Hours;
  1486.     time_t    Minutes;
  1487.     time_t    Seconds;
  1488.     MERIDIAN    Meridian;
  1489.     DSTMODE    DSTmode;
  1490. {
  1491.     static int DaysInMonth[12] = {
  1492.     31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  1493.     };
  1494.     time_t    tod;
  1495.     time_t    Julian;
  1496.     int        i;
  1497.  
  1498.     if (Year < 0)
  1499.     Year = -Year;
  1500.     if (Year < 100)
  1501.     Year += 1900;
  1502.     DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
  1503.             ? 29 : 28;
  1504.     if (Year < EPOCH || Year > 1999
  1505.      || Month < 1 || Month > 12
  1506.      /* Lint fluff:  "conversion from long may lose accuracy" */
  1507.      || Day < 1 || Day > DaysInMonth[(int)--Month])
  1508.     return -1;
  1509.  
  1510.     for (Julian = Day - 1, i = 0; i < Month; i++)
  1511.     Julian += DaysInMonth[i];
  1512.     for (i = EPOCH; i < Year; i++)
  1513.     Julian += 365 + (i % 4 == 0);
  1514.     Julian *= SECSPERDAY;
  1515.     Julian += yyTimezone * 60L;
  1516.     if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
  1517.     return -1;
  1518.     Julian += tod;
  1519.     if (DSTmode == DSTon
  1520.      || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
  1521.     Julian -= 60 * 60;
  1522.     return Julian;
  1523. }
  1524.  
  1525.  
  1526. static time_t
  1527. DSTcorrect(Start, Future)
  1528.     time_t    Start;
  1529.     time_t    Future;
  1530. {
  1531.     time_t    StartDay;
  1532.     time_t    FutureDay;
  1533.  
  1534.     StartDay = (localtime(&Start)->tm_hour + 1) % 24;
  1535.     FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
  1536.     return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
  1537. }
  1538.  
  1539.  
  1540. static time_t
  1541. RelativeDate(Start, DayOrdinal, DayNumber)
  1542.     time_t    Start;
  1543.     time_t    DayOrdinal;
  1544.     time_t    DayNumber;
  1545. {
  1546.     struct tm    *tm;
  1547.     time_t    now;
  1548.  
  1549.     now = Start;
  1550.     tm = localtime(&now);
  1551.     now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
  1552.     now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  1553.     return DSTcorrect(Start, now);
  1554. }
  1555.  
  1556.  
  1557. static time_t
  1558. RelativeMonth(Start, RelMonth)
  1559.     time_t    Start;
  1560.     time_t    RelMonth;
  1561. {
  1562.     struct tm    *tm;
  1563.     time_t    Month;
  1564.     time_t    Year;
  1565.  
  1566.     if (RelMonth == 0)
  1567.     return 0;
  1568.     tm = localtime(&Start);
  1569.     Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
  1570.     Year = Month / 12;
  1571.     Month = Month % 12 + 1;
  1572.     return DSTcorrect(Start,
  1573.         Convert(Month, (time_t)tm->tm_mday, Year,
  1574.         (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
  1575.         MER24, DSTmaybe));
  1576. }
  1577.  
  1578.  
  1579. static int
  1580. LookupWord(buff)
  1581.     char        *buff;
  1582. {
  1583.     register char    *p;
  1584.     register char    *q;
  1585.     register const TABLE    *tp;
  1586.     int            i;
  1587.     int            abbrev;
  1588.  
  1589.     /* Make it lowercase. */
  1590.     for (p = buff; *p; p++)
  1591.     if (isupper(*p))
  1592.         *p = tolower(*p);
  1593.  
  1594.     if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
  1595.     yylval.Meridian = MERam;
  1596.     return tMERIDIAN;
  1597.     }
  1598.     if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
  1599.     yylval.Meridian = MERpm;
  1600.     return tMERIDIAN;
  1601.     }
  1602.  
  1603.     /* See if we have an abbreviation for a month. */
  1604.     if (strlen(buff) == 3)
  1605.     abbrev = 1;
  1606.     else if (strlen(buff) == 4 && buff[3] == '.') {
  1607.     abbrev = 1;
  1608.     buff[3] = '\0';
  1609.     }
  1610.     else
  1611.     abbrev = 0;
  1612.  
  1613.     for (tp = MonthDayTable; tp->name; tp++) {
  1614.     if (abbrev) {
  1615.         if (strncmp(buff, tp->name, 3) == 0) {
  1616.         yylval.Number = tp->value;
  1617.         return tp->type;
  1618.         }
  1619.     }
  1620.     else if (strcmp(buff, tp->name) == 0) {
  1621.         yylval.Number = tp->value;
  1622.         return tp->type;
  1623.     }
  1624.     }
  1625.  
  1626.     for (tp = TimezoneTable; tp->name; tp++)
  1627.     if (strcmp(buff, tp->name) == 0) {
  1628.         yylval.Number = tp->value;
  1629.         return tp->type;
  1630.     }
  1631.  
  1632.     if (strcmp(buff, "dst") == 0) 
  1633.     return tDST;
  1634.  
  1635.     for (tp = UnitsTable; tp->name; tp++)
  1636.     if (strcmp(buff, tp->name) == 0) {
  1637.         yylval.Number = tp->value;
  1638.         return tp->type;
  1639.     }
  1640.  
  1641.     /* Strip off any plural and try the units table again. */
  1642.     i = strlen(buff) - 1;
  1643.     if (buff[i] == 's') {
  1644.     buff[i] = '\0';
  1645.     for (tp = UnitsTable; tp->name; tp++)
  1646.         if (strcmp(buff, tp->name) == 0) {
  1647.         yylval.Number = tp->value;
  1648.         return tp->type;
  1649.         }
  1650.     buff[i] = 's';        /* Put back for "this" in OtherTable. */
  1651.     }
  1652.  
  1653.     for (tp = OtherTable; tp->name; tp++)
  1654.     if (strcmp(buff, tp->name) == 0) {
  1655.         yylval.Number = tp->value;
  1656.         return tp->type;
  1657.     }
  1658.  
  1659.     /* Military timezones. */
  1660.     if (buff[1] == '\0' && isalpha(*buff)) {
  1661.     for (tp = MilitaryTable; tp->name; tp++)
  1662.         if (strcmp(buff, tp->name) == 0) {
  1663.         yylval.Number = tp->value;
  1664.         return tp->type;
  1665.         }
  1666.     }
  1667.  
  1668.     /* Drop out any periods and try the timezone table again. */
  1669.     for (i = 0, p = q = buff; *q; q++)
  1670.     if (*q != '.')
  1671.         *p++ = *q;
  1672.     else
  1673.         i++;
  1674.     *p = '\0';
  1675.     if (i)
  1676.     for (tp = TimezoneTable; tp->name; tp++)
  1677.         if (strcmp(buff, tp->name) == 0) {
  1678.         yylval.Number = tp->value;
  1679.         return tp->type;
  1680.         }
  1681.  
  1682.     return tID;
  1683. }
  1684.  
  1685.  
  1686. static int
  1687. yylex()
  1688. {
  1689.     register char    c;
  1690.     register char    *p;
  1691.     char        buff[20];
  1692.     int            Count;
  1693.     int            sign;
  1694.  
  1695.     for ( ; ; ) {
  1696.     while (isspace(*yyInput))
  1697.         yyInput++;
  1698.  
  1699.     if (isdigit(c = *yyInput) || c == '-' || c == '+') {
  1700.         if (c == '-' || c == '+') {
  1701.         sign = c == '-' ? -1 : 1;
  1702.         if (!isdigit(*++yyInput))
  1703.             /* skip the '-' sign */
  1704.             continue;
  1705.         }
  1706.         else
  1707.         sign = 0;
  1708.         for (yylval.Number = 0; isdigit(c = *yyInput++); )
  1709.         yylval.Number = 10 * yylval.Number + c - '0';
  1710.         yyInput--;
  1711.         if (sign < 0)
  1712.         yylval.Number = -yylval.Number;
  1713.         return sign ? tSNUMBER : tUNUMBER;
  1714.     }
  1715.     if (isalpha(c)) {
  1716.         for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
  1717.         if (p < &buff[sizeof buff - 1])
  1718.             *p++ = c;
  1719.         *p = '\0';
  1720.         yyInput--;
  1721.         return LookupWord(buff);
  1722.     }
  1723.     if (c != '(')
  1724.         return *yyInput++;
  1725.     Count = 0;
  1726.     do {
  1727.         c = *yyInput++;
  1728.         if (c == '\0')
  1729.         return c;
  1730.         if (c == '(')
  1731.         Count++;
  1732.         else if (c == ')')
  1733.         Count--;
  1734.     } while (Count > 0);
  1735.     }
  1736. }
  1737.  
  1738.  
  1739. time_t
  1740. get_date(p, now)
  1741.     char        *p;
  1742.     struct timeb    *now;
  1743. {
  1744.     struct tm        *tm;
  1745.     struct timeb    ftz;
  1746.     time_t        Start;
  1747.     time_t        tod;
  1748.  
  1749.     yyInput = p;
  1750.     if (now == NULL) {
  1751.         now = &ftz;
  1752. #if    !defined(HAVE_FTIME)
  1753.     (void)time(&ftz.time);
  1754.     /* Set the timezone global. */
  1755.     tzset();
  1756.     {
  1757. #if sgi
  1758.         ftz.timezone = (int) _timezone / 60;
  1759. #else /* not sgi */
  1760. #ifdef __386BSD__
  1761.         ftz.timezone = 0;
  1762. #else /* neither sgi nor 386BSD */
  1763. #if defined (USG)
  1764.         extern time_t timezone;
  1765.  
  1766.         ftz.timezone = (int) timezone / 60;
  1767. #else /* neither sgi nor 386BSD nor USG */
  1768.         struct timeval tv;
  1769.         struct timezone tz;
  1770.  
  1771.         gettimeofday (&tv, &tz);
  1772.         ftz.timezone = (int) tz.tz_minuteswest;
  1773. #endif /* neither sgi nor 386BSD nor USG */
  1774. #endif /* neither sgi nor 386BSD */
  1775. #endif /* not sgi */
  1776.     }
  1777. #else /* HAVE_FTIME */
  1778.     (void)ftime(&ftz);
  1779. #endif /* HAVE_FTIME */
  1780.     }
  1781.  
  1782.     tm = localtime(&now->time);
  1783.     yyYear = tm->tm_year;
  1784.     yyMonth = tm->tm_mon + 1;
  1785.     yyDay = tm->tm_mday;
  1786.     yyTimezone = now->timezone;
  1787.     yyDSTmode = DSTmaybe;
  1788.     yyHour = 0;
  1789.     yyMinutes = 0;
  1790.     yySeconds = 0;
  1791.     yyMeridian = MER24;
  1792.     yyRelSeconds = 0;
  1793.     yyRelMonth = 0;
  1794.     yyHaveDate = 0;
  1795.     yyHaveDay = 0;
  1796.     yyHaveRel = 0;
  1797.     yyHaveTime = 0;
  1798.     yyHaveZone = 0;
  1799.  
  1800.     if (yyparse()
  1801.      || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
  1802.     return -1;
  1803.  
  1804.     if (yyHaveDate || yyHaveTime || yyHaveDay) {
  1805.     Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
  1806.             yyMeridian, yyDSTmode);
  1807.     if (Start < 0)
  1808.         return -1;
  1809.     }
  1810.     else {
  1811.     Start = now->time;
  1812.     if (!yyHaveRel)
  1813.         Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
  1814.     }
  1815.  
  1816.     Start += yyRelSeconds;
  1817.     Start += RelativeMonth(Start, yyRelMonth);
  1818.  
  1819.     if (yyHaveDay && !yyHaveDate) {
  1820.     tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
  1821.     Start += tod;
  1822.     }
  1823.  
  1824.     /* Have to do *something* with a legitimate -1 so it's distinguishable
  1825.      * from the error return value.  (Alternately could set errno on error.) */
  1826.     return Start == -1 ? 0 : Start;
  1827. }
  1828.  
  1829.  
  1830. #if    defined(TEST)
  1831.  
  1832. /* ARGSUSED */
  1833. main(ac, av)
  1834.     int        ac;
  1835.     char    *av[];
  1836. {
  1837.     char    buff[128];
  1838.     time_t    d;
  1839.  
  1840.     (void)printf("Enter date, or blank line to exit.\n\t> ");
  1841.     (void)fflush(stdout);
  1842.     while (gets(buff) && buff[0]) {
  1843.     d = get_date(buff, (struct timeb *)NULL);
  1844.     if (d == -1)
  1845.         (void)printf("Bad format - couldn't convert.\n");
  1846.     else
  1847.         (void)printf("%s", ctime(&d));
  1848.     (void)printf("\t> ");
  1849.     (void)fflush(stdout);
  1850.     }
  1851.     exit(0);
  1852.     /* NOTREACHED */
  1853. }
  1854. #endif    /* defined(TEST) */
  1855.